local skel = fk.CreateSkill {
  name = "rmt__xuanwei",
  tags = {Skill.Limited, Skill.Lord},
}

skel:addEffect("viewas", {
  anim_type = "control",
  pattern = "nullification",
  prompt = "#rmt__xuanwei",
  interaction = function (self, player)
    local choices = {"rmt__xuanwei"}
    if player:hasSkill("rmt__sichan", true) then
      table.insert(choices, 1, "rmt__sichan")
    end
    return UI.ComboBox{ choices = choices }
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    if self.interaction.data == nil then return nil end
    local card = Fk:cloneCard("nullification")
    card.skillName = skel.name
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    room:addTableMark(player, skel.name, self.interaction.data)
    room:handleAddLoseSkills(player, "-"..self.interaction.data)
  end,
  enabled_at_nullification = function (self, player, data)
    return player:usedSkillTimes(skel.name, Player.HistoryGame) == 0 and
    data.to and data.to.kingdom == "qin"
  end,
})

skel:addEffect(fk.Damaged, {
  is_delay_effect = true,
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return target == player and not player.dead and player:getMark("rmt__xuanwei") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local skills = table.filter(player:getMark("rmt__xuanwei"), function(s)
      return not player:hasSkill(s, true)
    end)
    room:setPlayerMark(player, "rmt__xuanwei", 0)
    if #skills > 0 then
      room:handleAddLoseSkills(player, skills)
    end
  end,
})

skel:addAcquireEffect(function (self, player, is_death)
  player:setSkillUseHistory(self.name, 0, Player.HistoryGame)
end)

Fk:loadTranslationTable{
  ["rmt__xuanwei"] = "宣慰",
  [":rmt__xuanwei"] = "主公技，限定技，当锦囊牌对秦势力角色生效前，你可以失去此武将牌上的一个技能，视为使用【无懈可击】；直到你下次受到伤害，"..
  "恢复并复原失去的技能。",
  ["#rmt__xuanwei"] = "宣慰：你可以失去一个技能直到你下次受到伤害，视为使用【无懈可击】！",
  ["#rmt__xuanwei-choice"] = "宣慰：选择失去一个技能直到你下次受到伤害",

  ["$rmt__xuanwei1"] = "陛下命臣以龙骧建业，臣领命，不敢违。",
  ["$rmt__xuanwei2"] = "吾不及亡兄有四，幸算中群贤之能。",
}

return skel
